package zhoufu.sz.sanxiao_check.utils;

import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.support.v4.content.FileProvider;

import java.io.File;

import zhoufu.sz.sanxiao_check.BuildConfig;

/**
 * 自定义一个Provider，以免和引入的项目的provider冲突
 *
 * Author: nanchen
 * Email: liushilin520@foxmail.com
 * Date: 2017-03-17  16:10
 */

public class ImagePickerProvider extends FileProvider {

    /**
     * 获取uri，兼容7.0
     *
     * @param uri
     * @return
     */
    public static Uri getProviderUri(Context context, String uri) {
        if(Build.VERSION.SDK_INT>=24){
            File gridmanager = new File(uri);
            if(!gridmanager.exists())
                gridmanager.mkdir();
            return getUriForFile(context, BuildConfig.APPLICATION_ID+".provider",gridmanager);
        }
        return Uri.fromFile(new File(uri));
    }

    /**
     * 获取uri，兼容7.0
     *
     * @param uri
     * @return
     */
    public static Uri getProviderUri(Context context, File uri) {
        if(Build.VERSION.SDK_INT>=24){
            return getUriForFile(context,BuildConfig.APPLICATION_ID+".provider",uri);
        }
        return Uri.fromFile(uri);
    }
}